package com.cat.greedyAlgorithm;

import java.util.Arrays;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/maximum-element-after-decreasing-and-rearranging/description/
 * @create 2025/8/21 16:55
 * @since JDK17
 */

public class Solution10 {
    public int maximumElementAfterDecrementingAndRearranging(int[] arr) {
        Arrays.sort(arr);
        int n = arr.length;
        arr[0] = 1;
        for (int i = 1; i < n; i++) {
            if (arr[i] - arr[i - 1] > 1) {  // 不满足条件
                arr[i] = arr[i - 1] + 1;
            }
        }
        return arr[n - 1];
    }
}
